var http;

window.onload = loadfeeds;

function loadfeeds()
{
    http = new XMLHttpRequest();
    http.onreadystatechange = function()
    {
        if (http.readyState == 4 && http.status == 200)
        {
            var div_feeds = document.getElementById("feeds");
            div_feeds.innerHTML = http.responseText;
        }
    };
    http.open("GET", "loadFeeds.aspx?t="+Math.random(), true);
    http.send();
}

function postfeed()
{
    if(document.getElementById("postfeed").value.replace(/(^\s*)|(\s*$)/g,"") == "")
    {
        alert("您不能发布空的动态");
        return;
    }
    http = new XMLHttpRequest();
    http.onreadystatechange = function()
    {
        if(http.readyState == 4 && http.status == 200)
        {
            if(http.responseText == "1")
            {
                alert("success!");
                document.getElementById("postfeed").value = "";
                loadfeeds();
            }
            else
            {
                alert("failed!" + http.responseText);
            }
        }
    };
    http.open("POST", "postFeed.aspx", true);
    http.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
    http.send("content="+document.getElementById("postfeed").value);
}

function deletefeed(postID)
{
    http = new XMLHttpRequest();
    http.onreadystatechange = function()
    {
        if(http.readyState == 4 && http.status == 200)
        {
            if(http.responseText == "1")
            {
                alert("success!");
                loadfeeds();
            }
            else
            {
                alert("failed!" + http.responseText);
            }
        }
    };
    http.open("GET", "deleteFeed.aspx?postID=" + postID, true);
    http.send();
}